//
//  BottomCollectionVIewCell.m
//  SpiritWalk
//
//  Created by dllo on 16/3/15.
//  Copyright © 2016年 王鑫. All rights reserved.
//

#import "BottomCollectionVIewCell.h"

#import "SNChart.h"

@interface BottomCollectionVIewCell ()<SNChartDataSource>

@end

@implementation BottomCollectionVIewCell

-(id)initWithFrame:(CGRect)frame{
    
    self=[super initWithFrame:frame];
    if (self) {
        [self setUpView];
    }
    
    return self;
}
-(void)setUpView{
    self.topView=[[UIView alloc] init];
      [self.contentView addSubview:self.topView];
    
    self.averageTitleLabel=[[UILabel alloc] init];
    self.averageTitleLabel.textAlignment=NSTextAlignmentCenter;
    self.averageTitleLabel.font=[UIFont systemFontOfSize:25];
    self.averageTitleLabel.textColor=[UIColor colorWithRed:0.32 green:0.32 blue:0.32 alpha:1];
    [self.topView addSubview:self.averageTitleLabel];
    
    self.averageLabel=[[UILabel alloc] init];
    self.averageLabel.textAlignment=NSTextAlignmentCenter;
    self.averageLabel.font=[UIFont systemFontOfSize:45];
    self.averageLabel.textColor=[UIColor colorWithRed:0.98 green:0.6 blue:0 alpha:1];
    [self.topView addSubview:self.averageLabel];
    
    
    self.tatalTitleLabel=[[UILabel alloc] init];
    self.tatalTitleLabel.textAlignment=NSTextAlignmentCenter;
    self.tatalTitleLabel.font=[UIFont systemFontOfSize:25];
    self.tatalTitleLabel.textColor=[UIColor colorWithRed:0.32 green:0.32 blue:0.32 alpha:1];
    [self.topView addSubview:self.tatalTitleLabel];
    
    self.tatalLabel=[[UILabel alloc] init];
    self.tatalLabel.textAlignment=NSTextAlignmentCenter;
    self.tatalLabel.font=[UIFont systemFontOfSize:45];
    self.tatalLabel.textColor=[UIColor colorWithRed:0.98 green:0.6 blue:0 alpha:1];
    [self.topView addSubview:self.tatalLabel];

   
    //chart.backgroundColor=[UIColor cyanColor];
}
-(void)createChart{
    CGFloat  chartHeight=HEIGHT-64-150*SCREENHEIGHT;
    SNChart * chart = [[SNChart alloc] initWithFrame:CGRectMake(-10, HEIGHT-64-chartHeight, self.frame.size.width, chartHeight) withDataSource:self andChatStyle:SNChartStyleBar];
    chart.kYEqualPaths=5;
    chart.chartBarTheYAxisSpan=(chartHeight-50)/5;
    [chart showInView:self];
}
-(void)setValueArr:(NSMutableArray *)valueArr{
    if (_valueArr!=valueArr) {
        _valueArr=valueArr;
        [self createChart];
    }
}
-(void)setTitleArr:(NSMutableArray *)titleArr{
    NSLog(@"asdassdas %@",titleArr);
    if (_titleArr!=titleArr) {
        _titleArr=titleArr;
    }
}
- (NSArray *)chatConfigYValue:(SNChart *)chart {
    NSLog(@"%@",self.valueArr);
    
    return self.valueArr;
 
}

- (NSArray *)chatConfigXValue:(SNChart *)chart {
    return self.titleArr;
}

-(void)layoutSubviews{
    [super layoutSubviews];
       
}


-(void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes{
    [super  applyLayoutAttributes:layoutAttributes];
    self.topView.frame=CGRectMake(0, 0, WIDTH, 130*SCREENHEIGHT);
    //self.averageTitleLabel.frame=CGRectMake(40, 40, 100, 40);
 //   self.averageLabel.frame=CGRectMake(40, 80, 160, 100);
    self.averageTitleLabel.frame=CGRectMake(0, 0, WIDTH/2, 130*SCREENHEIGHT/2);
    self.averageLabel.frame=CGRectMake(0, 130*SCREENHEIGHT/2, WIDTH/2, 130*SCREENHEIGHT/2);
    self.tatalTitleLabel.frame=CGRectMake(WIDTH/2, 0, WIDTH/2, 130*SCREENHEIGHT/2);
    self.tatalLabel.frame=CGRectMake( WIDTH/2, 130*SCREENHEIGHT/2, WIDTH/2, 130*SCREENHEIGHT/2);
   // self.tatalLabel.frame=CGRectMake(200, 80, 160, 100);
    
    
    
}

@end
